cmd line tutorials - gencmd

cmd line tutorials - gencmd

The ls Command

Unix-Linux Mac

The ls command is one of the most basic and commonly used command line tools in Unix-like operating systems. It is used to list the contents of a directory. The ls command is a very versatile tool that can be used to display a variety of information about the contents of a directory, including the file names, file sizes, file permissions, and file modification times.

Syntax

The basic syntax for the ls command is as follows:

ls [options] [directory]

The [directory] argument is the directory that you want to list the contents of. If you do not specify a directory, the ls command will list the contents of the current directory.

The [options] argument is a list of options that can be used to modify the behavior of the ls command.

Examples

List the contents of the current directory.

ls

List the contents of the directory /home/user.

ls /home/user

List the contents of the current directory in long format.

ls -l

List the contents of the current directory in reverse alphabetical order.

ls -r

List the contents of the current directory and all of its subdirectories.

ls -R

List the contents in long format of the current directory in reverse chronological order.

ls -lrt

Options

The ls command has a number of options that can be used to modify its behavior. Some of the most common options are:

-a: List all files, including hidden files.

-h: List file sizes in human-readable format (e.g., KB, MB, GB). For more information on the ls command and its options, please see the man page for ls.

With gencmd

gencmd show all details about all files in reverse chronological over

  • ls -lrta
  • ls -ltrah